package com.zhengshang.web.controller.app;

import java.util.List;

import com.zhengshang.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhengshang.common.annotation.Log;
import com.zhengshang.common.core.controller.BaseController;
import com.zhengshang.common.core.domain.AjaxResult;
import com.zhengshang.common.enums.BusinessType;
import com.zhengshang.api.domain.AppBank;
import com.zhengshang.api.service.IAppBankService;
import com.zhengshang.common.utils.poi.ExcelUtil;
import com.zhengshang.common.core.page.TableDataInfo;

/**
 * 银行Controller
 * 
 * @author zhengshang
 * @date 2021-06-01
 */
@RestController
@RequestMapping("/app/bank")
public class AppBankController extends BaseController
{
    @Autowired
    private IAppBankService appBankService;

    /**
     * 查询银行列表
     */
    @PreAuthorize("@ss.hasPermi('app:bank:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppBank appBank)
    {
        startPage();
        List<AppBank> list = appBankService.selectAppBankList(appBank);
        return getDataTable(list);
    }

    /**
     * 导出银行列表
     */
    @PreAuthorize("@ss.hasPermi('app:bank:export')")
    @Log(title = "银行", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppBank appBank)
    {
        List<AppBank> list = appBankService.selectAppBankList(appBank);
        ExcelUtil<AppBank> util = new ExcelUtil<AppBank>(AppBank.class);
        return util.exportExcel(list, "bank");
    }

    /**
     * 获取银行详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:bank:query')")
    @GetMapping(value = "/{bankId}")
    public AjaxResult getInfo(@PathVariable("bankId") Long bankId)
    {
        return AjaxResult.success(appBankService.selectAppBankById(bankId));
    }

    /**
     * 新增银行
     */
    @PreAuthorize("@ss.hasPermi('app:bank:add')")
    @Log(title = "银行", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppBank appBank)
    {
        appBank.setCreateBy(SecurityUtils.getUsername());
        return toAjax(appBankService.insertAppBank(appBank));
    }

    /**
     * 修改银行
     */
    @PreAuthorize("@ss.hasPermi('app:bank:edit')")
    @Log(title = "银行", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppBank appBank)
    {
        appBank.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(appBankService.updateAppBank(appBank));
    }

    /**
     * 删除银行
     */
    @PreAuthorize("@ss.hasPermi('app:bank:remove')")
    @Log(title = "银行", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bankIds}")
    public AjaxResult remove(@PathVariable Long[] bankIds)
    {
        return toAjax(appBankService.deleteAppBankByIds(bankIds));
    }
}
